# 设备模型
from tortoise.models import Model
from tortoise import fields


class Device(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=100)
    device_id = fields.CharField(max_length=50, unique=True)
    status = fields.CharField(max_length=20, default="offline")
    firmware_version = fields.CharField(max_length=20)
    last_seen = fields.DatetimeField(auto_now=True)
    owner = fields.ForeignKeyField('models.User', related_name='devices')


class FirmwareUpdate(Model):
    id = fields.IntField(pk=True)
    device = fields.ForeignKeyField('models.Device')
    version = fields.CharField(max_length=20)
    file_path = fields.CharField(max_length=200)
    status = fields.CharField(max_length=20, default="pending")
    created_at = fields.DatetimeField(auto_now_add=True)